<?php defined('SYSPATH') or die('No direct access allowed.');

include ("media/soap/synchclasses/webservice_classes.php");
include ("application/classes/helper/factoryDTO.php");

class Model_systoleSync extends Model{

	static $maxAmount = 20;

	/**
	 *
	 *
	 * @param uploadMedicine $parameters
	 * @return uploadMedicineResponse
	 */
	public function uploadMedicine($parameters) {
		if($parameters==null){
			return null;
		}
		$i = Helper_FactoryDTO::medicineDTOToEntity($parameters->in);
		$response = new uploadMedicineResponse();
		$response->out = $i;
		return $response;
	}

	/**
	 *
	 *
	 * @param uploadPathology $parameters
	 * @return uploadPathologyResponse
	 */
	public function uploadPathology($parameters) {
		if($parameters==null){
			return null;
		}
		$i= Helper_FactoryDTO::pathologyDTOToEntity($parameters->in);
		$response = new uploadPathologyResponse();
		$response->out = $i;
		return $response;
	}


	/**
	 *
	 *
	 * @param uploadProfession $parameters
	 * @return uploadProfessionResponse
	 */
	public function uploadProfession($parameters) {
		if($parameters==null){
			return null;
		}
		$i= Helper_FactoryDTO::professionDTOToEntity($parameters->in);
		$response = new uploadProfessionResponse();
		$response->out = $i;
		return $response;
	}

	/**
	 *
	 *
	 * @param uploadMedic $parameters
	 * @return uploadMedicResponse
	 */
	public function uploadMedic($parameters) {
		if($parameters==null){
			return null;
		}
		$i = Helper_FactoryDTO::medicDTOToEntity($parameters->in);
		$response = new uploadMedicResponse();
		$response->out = $i;
		return $response;
	}

	/**
	 *
	 *
	 * @param uploadSport $parameters
	 * @return uploadSportResponse
	 */
	public function uploadSport($parameters) {
		if($parameters==null){
			return null;
		}
		$i = Helper_FactoryDTO::sportDTOToEntity($parameters->in);
		$response = new uploadSportResponse();
		$response->out = $i;
		return $response;
	}

	/**
	 *
	 *
	 * @param uploadSurgery $parameters
	 * @return uploadSurgeryResponse
	 */
	public function uploadSurgery($parameters) {
		if($parameters==null){
			return null;
		}
		$i = Helper_FactoryDTO::surgeryDTOToEntity($parameters->in);
		$response = new uploadSurgeryResponse();
		$response->out = $i;
		return $response;
	}

	/**
	 *
	 *
	 * @param uploadFamily $parameters
	 * @return uploadFamilyResponse
	 */
	public function uploadFamily($parameters) {
		if($parameters==null){
			return null;
		}
		$i = Helper_FactoryDTO::familyDTOToEntity($parameters->in);
		$response = new uploadFamilyResponse();
		$response->out = $i;
		return $response;
	}

	/**
	 *
	 *
	 * @param uploadPatient $parameters
	 * @return uploadPatientResponse
	 */
	public function uploadPatient($parameters) {
		if($parameters==null){
			return null;
		}
		$i = Helper_FactoryDTO::patientDTOToEntity($parameters->in);
		$response = new uploadPatientResponse();
		$response->out = $i;
		return $response;
	}

	/**
	 *
	 *
	 * @param uploadAnalysis $parameters
	 * @return uploadAnalysisResponse
	 */
	public function uploadAnalysis($parameters) {
		if($parameters==null){
			return null;
		}
		$i = Helper_FactoryDTO::analysisDTOToEntity($parameters->in);
		$response = new uploadAnalysisResponse();
		$response->out = $i;
		return $response;
	}

	/**
	 *
	 * @param uploadIdentityCardType $parameters
	 * @return uploadIdentityCardTypeResponse
	 */
	public function uploadIdentityCardType($parameters){
		if($parameters==null){
			return null;
		}
		$i = Helper_FactoryDTO::identityCardTypeDTOToEntity($parameters->in);
		$response = new uploadIdentityCardTypeResponse();
		$response->out = $i;
		return $response;
	}


	/**
	 *
	 *
	 * @param uploadSignalFrequency $parameters
	 * @return uploadSignalFrequencyResponse
	 */
	public function uploadSignalFrequency($parameters) {
		if($parameters==null){
			return null;
		}
		$i = Helper_FactoryDTO::signalFrequencyDTOToEntity($parameters->in);
		$response = new uploadSignalFrequencyResponse();
		$response->out = $i;
		return $response;
	}

	/**
	 *
	 *
	 * @param downloadMedicines $parameters
	 * @return downloadMedicinesResponse
	 */
	public function downloadMedicines($parameters) {
		if($parameters==null){
			return null;
		}
		$medicineDao = Helper_Service::factory("medicine");
		$medicines = $medicineDao->getListFromMinID($parameters->in->remote_id,self::$maxAmount);
		$i=0;
		$last_id =0;
		$medicinesDTO = array();
		foreach ($medicines as $medicine){
			$medicinesDTO[$i] = Helper_FactoryDTO::entityToMedicineDTO($medicine);
			$last_id = $medicine->id;
			$i++;
		}
		$medicinePage = new medicines_page();
		$medicinePage->max_id = $last_id;
		$medicinePage->medicines = $medicinesDTO;
		$downloadResponse = new downloadMedicinesResponse();
		$downloadResponse->out = $medicinePage;
		return $downloadResponse;
	}

	/**
	 *
	 * @param downloadIdentityCardTypes $parameters
	 *  @return downloadIdentityCardTypesResponse
	 */
	public function downloadIdentityCardTypes($parameters){
		if($parameters==null){
			return null;
		}
		$identityCardDao = Helper_Service::factory("identitycard");
		$cardtypes = $identityCardDao->getListFromMinID($parameters->in->remote_id,self::$maxAmount);
		$i=0;
		$last_id =0;
		$cardTypesDTO = array();
		foreach ($cardtypes as $cardType){
			$cardTypesDTO[$i] = Helper_FactoryDTO::entityToIdentityCardTypeDTO($cardType);
			$last_id = $cardType->id;
			$i++;
		}
		$identityCards = new identity_cards_page();
		$identityCards->max_id = $last_id;
		$identityCards->identity_cards = $cardTypesDTO;
		$downloadResponse = new downloadIdentityCardTypesResponse();
		$downloadResponse->out = $identityCards;
		return $downloadResponse;
	}

	/**
	 *
	 *
	 * @param downloadPathologies $parameters
	 * @return downloadPathologiesResponse
	 */
	public function downloadPathologies($parameters) {
		if($parameters==null){
			return null;
		}
		$pathologyDao = Helper_Service::factory("pathology");
		$pathologies = $pathologyDao->getListFromMinID($parameters->in->remote_id,self::$maxAmount);
		$i=0;
		$last_id =0;
		$pathologiesDTO = array();
		foreach ($pathologies as $pathology){
			$pathologiesDTO[$i] = Helper_FactoryDTO::entityToPathologyDTO($pathology);
			$last_id = $pathology->id;
			$i++;
		}
		$pathologyPage = new pathologies_page();
		$pathologyPage->max_id = $last_id;
		$pathologyPage->pathologies = $pathologiesDTO;
		$downloadResponse = new downloadPathologiesResponse();
		$downloadResponse->out = $pathologyPage;
		return $downloadResponse;
	}

	/**
	 *
	 *
	 * @param downloadMedics $parameters
	 * @return downloadMedicsResponse
	 */
	public function downloadMedics($parameters) {
		if($parameters==null){
			return null;
		}
		$medicDao = Helper_Service::factory("medic");
		$medics = $medicDao->getListFromMinID($parameters->in->remote_id,self::$maxAmount);
		$i=0;
		$last_id =0;
		$medicsDTO = array();
		foreach ($medics as $medic){
			$medicsDTO[$i] = Helper_FactoryDTO::entityToMedicDTO($medic);
			$last_id = $medic->id;
			$i++;
		}
		$medicPage = new medics_page();
		$medicPage->max_id = $last_id;
		$medicPage->medics = $medicsDTO;
		$downloadResponse = new downloadMedicsResponse();
		$downloadResponse->out = $medicPage;
		return $downloadResponse;
	}

	/**
	 *
	 *
	 * @param downloadSports $parameters
	 * @return downloadSportsResponse
	 */
	public function downloadSports($parameters) {
		if($parameters==null){
			return null;
		}
		$sportDao = Helper_Service::factory("sport");
		$sports = $sportDao->getListFromMinID($parameters->in->remote_id,self::$maxAmount);
		$i=0;
		$last_id =0;
		$sportsDTO = array();
		foreach ($sports as $sport){
			$sportsDTO[$i] = Helper_FactoryDTO::entityToSportDTO($sport);
			$last_id = $sport->id;
			$i++;
		}
		$sportPage = new sports_page();
		$sportPage->max_id = $last_id;
		$sportPage->sports = $sportsDTO;
		$downloadResponse = new downloadSportsResponse();
		$downloadResponse->out = $sportPage;
		return $downloadResponse;
	}




	/**
	 *
	 *
	 * @param downloadSurgeries $parameters
	 * @return downloadSurgeriesResponse
	 */
	public function downloadSurgeries($parameters) {
		if($parameters==null){
			return null;
		}
		$surgeryDao = Helper_Service::factory("surgery");
		$surgeries = $surgeryDao->getListFromMinID($parameters->in->remote_id,self::$maxAmount);
		$i=0;
		$last_id =0;
		$surgeriesDTO = array();
		foreach ($surgeries as $surgery){
			$surgeriesDTO[$i] = Helper_FactoryDTO::entityToSurgeryDTO($surgery);
			$last_id = $surgery->id;
			$i++;
		}
		$surgeryPage = new surgeries_page();
		$surgeryPage->max_id = $last_id;
		$surgeryPage->surgeries = $surgeriesDTO;
		$downloadResponse = new downloadSurgeriesResponse();
		$downloadResponse->out = $surgeryPage;
		return $downloadResponse;
	}

	/**
	 *
	 *
	 * @param downloadFamily $parameters
	 * @return downloadFamilyResponse
	 */
	public function downloadFamily($parameters) {
		if($parameters==null){
			return null;
		}
		$familyDao = Helper_Service::factory("family");
		$families = $familyDao->getListFromMinID($parameters->in->remote_id,self::$maxAmount);
		$i=0;
		$last_id =0;
		$familiesDTO = array();
		foreach ($families as $family){
			$familiesDTO[$i] = Helper_FactoryDTO::entityToFamilyDTO($family);
			$last_id = $family->id;
			$i++;
		}
		$familyPage = new family_page();
		$familyPage->max_id = $last_id;
		$familyPage->family = $familiesDTO;
		$downloadResponse = new downloadFamilyResponse();
		$downloadResponse->out = $familyPage;
		return $downloadResponse;
	}

	/**
	 *
	 *
	 * @param downloadPatients $parameters
	 * @return downloadPatientsResponse
	 */
	public function downloadPatients($parameters) {
		if($parameters==null){
			return null;
		}

		$patientDao = Helper_Service::factory("patient");
		$patients = $patientDao->getListFromMinID($parameters->in->remote_id,self::$maxAmount);
		$i=0;
		$last_id =0;
		$patientsDTO = array();
		foreach ($patients as $patient){
			$patientsDTO[$i] = Helper_FactoryDTO::entityToPatientDTO($patient);
			$last_id = $patient->id;
			$i++;
		}
		$patientsPage = new patients_page();
		$patientsPage->max_id = $last_id;
		$patientsPage->patients = $patientsDTO;
		$downloadResponse = new downloadPatientsResponse();
		$downloadResponse->out=$patientsPage;
		return $downloadResponse;
	}


	/**
	 *
	 *
	 * @param downloadProffesions $parameters
	 * @return downloadProfessionsResponse
	 */
	public function downloadProfessions($parameters) {
		if($parameters==null){
			return null;
		}
		$professionDao = Helper_Service::factory("profession");
		$professions = $professionDao->getListFromMinID($parameters->in->remote_id,self::$maxAmount);
		$i=0;
		$last_id =0;
		$professionsDTO = array();
		foreach ($professions as $profession){
			$professionsDTO[$i] = Helper_FactoryDTO::entityToProfessionDTO($profession);
			$last_id = $profession->id;
			$i++;
		}
		$professionPage = new professions_page();
		$professionPage->max_id = $last_id;
		$professionPage->professions = $professionsDTO;
		$downloadResponse = new downloadProfessionsResponse();
		$downloadResponse->out = $professionPage;
		return $downloadResponse;
	}


	/**
	 *
	 *
	 * @param downloadSignalFrequency $parameters
	 * @return downloadSignalFrequencyResponse
	 */
	public function downloadSignalFrequency($parameters) {
		if($parameters==null){
			return null;
		}
		$frequencyDao = Helper_Service::factory("samplingperiod");
		$frequencies = $frequencyDao->getListFromMinID($parameters->in->remote_id,self::$maxAmount);
		$i=0;
		$last_id =0;
		$frequenciesDTO = array();
		foreach ($frequencies as $frequency){
			$frequenciesDTO[$i] = Helper_FactoryDTO::entityToSignalFrequencyDTO($frequency);
			$last_id = $frequency->id;
			$i++;
		}
		$frequencyPage = new signal_frequency_page();
		$frequencyPage->max_id = $last_id;
		$frequencyPage->frequencies = $frequenciesDTO;
		$downloadResponse = new downloadSignalFrequencyResponse();
		$downloadResponse->out = $frequencyPage;
		return $downloadResponse;
	}

	/**
	 *
	 *
	 * @param downloadAverages $parameters
	 * @return downloadAveragesResponse
	 */
	public function downloadAverages($parameters) {

		$averageDao = Helper_Service::factory("statistics");
		$averages = $averageDao->getList();
		$averagesDTO = array();
		$i=0;
		foreach ($averages as $average){
			
			$averageWS = new averages_ws();
			$averageWS->decade = $average[0];
			$averageWS->sex = ($average[1]=="Masculino");
			$averageWS->aod_avg= $average[2];
			$averageWS->aod_trust_interval= $average[3];
			$averageWS->aos_avg= $average[4];
			$averageWS->aos_trust_interval= $average[5];
			$averageWS->iar_avg= $average[6];
			$averageWS->iar_trust_interval= $average[7];
			$averageWS->samples = $average[8];
			$averagesDTO[$i] = $averageWS;
			$i++;
		}
		$averagesWS = new averages_ws();
		$averagesWS->averages = $averagesDTO;
		$downloadResponse = new downloadAveragesResponse();
		$downloadResponse->out = $averagesWS;
		return $downloadResponse;
	}

	/**
	 *
	 *
	 * @param mergeMedicine $parameters
	 * @return mergeMedicineResponse
	 */
	public function mergeMedicine($parameters) {

	}

	/**
	 *
	 *
	 * @param mergePathology $parameters
	 * @return mergePathologyResponse
	 */
	public function mergePathology($parameters) {
			
	}

	/**
	 *
	 *
	 * @param mergeMedic $parameters
	 * @return mergeMedicResponse
	 */
	public function mergeMedic($parameters) {

	}

	/**
	 *
	 *
	 * @param mergeSport $parameters
	 * @return mergeSportResponse
	 */
	public function mergeSport($parameters) {

	}

	/**
	 *
	 *
	 * @param mergeSurgery $parameters
	 * @return mergeSurgeryResponse
	 */
	public function mergeSurgery($parameters) {

	}

	/**
	 *
	 *
	 * @param mergeFamily $parameters
	 * @return mergeFamilyResponse
	 */
	public function mergeFamily($parameters) {

	}

	/**
	 *
	 *
	 * @param mergePatient $parameters
	 * @return mergePatientResponse
	 */
	public function mergePatient($parameters) {

	}

	/**
	 *
	 *
	 * @param mergeAnalysis $parameters
	 * @return mergeAnalysisResponse
	 */
	public function mergeAnalysis($parameters) {

	}

	/**
	 *
	 *
	 * @param mergeSignalFrequency $parameters
	 * @return mergeSignalFrequencyResponse
	 */
	public function mergeSignalFrequency($parameters) {

	}

	/**
	 *
	 *
	 * @param uploadClinicalInformation $parameters
	 * @return uploadClinicalInformationResponse
	 */
	public function uploadClinicalInformation($parameters) {
		if ($parameters==null){
			return null;
		}
		$i = Helper_FactoryDTO::clinicalInfoDTOToEntity($parameters->in);
		$response = new uploadClinicalInformationResponse();
		$response->out = $i;
		return $response;
	}

	/**
	 *
	 *
	 * @param downloadClinicalInformation $parameters
	 * @return downloadClinicalInformationResponse
	 */
	public function downloadClinicalInformation($parameters) {
		if($parameters==null){
			return null;
		}
		$clinicalInfoDao = Helper_Service::factory("clinicalinformation");
		$clinicalInfoList = $clinicalInfoDao->getListFromMinID($parameters->in->remote_id,self::$maxAmount);
		$i=0;
		$last_id =0;
		$clinicalInfoListDTO = array();
		foreach ($clinicalInfoList as $clinicalInfo){
			$clinicalInfoListDTO[$i] = Helper_FactoryDTO::entityToClinicalInfoDTO($clinicalInfo);
			$last_id = $clinicalInfo->id;
			$i++;
		}
		$clinicalInfoPage = new clinical_info_page();
		$clinicalInfoPage->max_id = $last_id;
		$clinicalInfoPage->clinical_info_list = $clinicalInfoListDTO;
		$downloadResponse = new downloadClinicalInformationResponse();
		$downloadResponse->out = $clinicalInfoPage;
		return $downloadResponse;
	}

	/**
	 *
	 *
	 * @param mergeClinicalInformation $parameters
	 * @return mergeClinicalInformationResponse
	 */
	public function mergeClinicalInformation($parameters) {

	}



}

?>